package org.lex.notepad.util;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {
	static {
		// core=2; max=100; keepAliveTime=120s
		pool = new ThreadPoolExecutor(2, 100, 120L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
	}
	private static final ExecutorService pool;

	private ThreadPool() {
		super();
	}

	public static synchronized void execute(Runnable command) {
		pool.execute(command);
	}

	public static synchronized <T> Future<T> submit(Callable<T> task) {
		return pool.submit(task);
	}
}
